package cn.kgc.shiro.web.handlers;

import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 课工场
 * @date 2024/8/22
 * @description
 */
@RestControllerAdvice
public class GlobalExceptionHandler {


    @ExceptionHandler(Exception.class)
    public Map<String, Object>  allExceptionHandler(Exception e){

        HashMap<String, Object> map = new HashMap<>();
        map.put("code",500);
        map.put("message","服务器异常,请刷新重试...");
        return map;
    }

    @ExceptionHandler(UnauthorizedException.class)
    public Map<String, Object>  allExceptionHandler(UnauthorizedException e){


        HashMap<String, Object> map = new HashMap<>();
        map.put("code",403);
        map.put("message","没有权限,请联系管理员...");
        return map;
    }
}
